package com.zhao.Others;

import com.zhao.pojo.DrivingLicense;
import com.zhao.pojo.Ebick;
import com.zhao.pojo.Student;

import java.util.Date;

/**
 * 1.生成行驶证
 * 2.生成行驶证号码
 * 3.成随机的、唯一的车牌号
 * 4.生成举报单号
 */
public class GenerateObject {

    ////生成订单号   根据  卖方ID + 买方ID + 电动车ID
    public static String getOrderFormID(String sellID,String buyID,String ebickID){
        return sellID+buyID+ebickID;
    }

    //！！！！！生成图片名称
    public static String getNameOfPicture(String directoryName ,String universityID ,String userID){
        String newName = userID+ DateAndTimeObject.getOnlyNumberOfNowDate()+DateAndTimeObject.getOnlyNumberOfNowTime();
        return newName;
    }

    //生成举报单号!!!  被举报车牌号+日期+时间
    public static String getSuperviseID(String ebickID){

        String date = DateAndTimeObject.getOnlyNumberOfNowDate();
        String time = DateAndTimeObject.getOnlyNumberOfNowTime();

        String superviseID = ebickID + date + time;

        return superviseID;
    }


    //生成行驶证
    public static DrivingLicense generateDrivingLicense(Student student,Ebick ebick){

        DrivingLicense drivingLicense = new DrivingLicense();

        String drivingLicenseID = generateDrivingLicenseID(student,ebick);

        drivingLicense.setDrivingLicenseID(drivingLicenseID);
        drivingLicense.setEbickID(ebick.getEbickID());
        drivingLicense.setOwnerID(student.getStudentID());
        drivingLicense.setUniversityID(student.getUniversityID());

        //获得系统时间  作为 行驶证生效时间
        String generateTime = DateAndTimeObject.getNowDate();
        drivingLicense.setGenerateTime(generateTime);

        return  drivingLicense;
    }

    //行驶证号生成的方法   学校简称+学校ID+学院ID+专业ID+班级+电动车ID
    public static String generateDrivingLicenseID(Student student, Ebick ebick){

        System.out.println("generating drivingLicenseID");

        if(student.getUniversityID()==null ||
                student.getDepartmentID()==null ||
                student.getMajorID()==null ||
                student.getStuClass()==null ||
                ebick.getEbickID()==null)
        {
            return "error";
        }

        String drivingLicenseID =
                ebick.getEbickID().substring(0,1) +
                student.getUniversityID() +
                student.getDepartmentID() +
                student.getMajorID() +
                        student.getStuClass() +
                ebick.getEbickID().substring(1,ebick.getEbickID().length());

        return drivingLicenseID;
    }

    //生成随机的  唯一的 车牌号
    //学校简称+6位数字
    //shortName 是学校的简称
    public static String generateEbickID(String shortName){

        System.out.println("generating EbickID");

        //生成一个0-9999之间不重复的随机数
        int num= (int) (Math.random()*100000);
        String realNum=Integer.toString(num);

        //不足六位前面补零
        if(num<100000){
            int i = 6 - realNum.length();
            //System.out.println(i);
            for(;i>0;i--){
                realNum="0"+realNum;
            }

        }

        String EbickID=shortName+realNum;

        return EbickID;
    }

    public static void main(String[] args) {

        /*Ebick ebick = new Ebick();
        ebick.setEbickID(generateEbickID("燕"));

        Student student = new Student();
        student.setUniversityID("001");
        student.setDepartmentID("04");
        student.setMajorID("21");
        student.setStuClass("1804");
        System.out.println(generateDrivingLicenseID(student,ebick));

        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(date.format(new Date()));*/


    }

}
